<!--  -->
<template>
  <div class="app-menbermanage">
    <top-header></top-header>
    <div class="collect-box">
      <div class="box-top">
        <h3 v-for="(item, index) in this.$route.meta" :key="index">
          {{ item }}
        </h3>
          <el-button size="mini" style="width:120px;">添加会员</el-button>
        <div class="input">
          <input type="text" placeholder="请输入关键字" v-model="inputVal" />
          <el-button size="mini" style="border-left:1px solid #ddd">搜索</el-button>
        </div>
      </div>
      <div class="box-bottom">
        <el-table :data="menberData" style="width: 100%">
          <el-table-column type="index" label="#" width="180">
          </el-table-column>
          <el-table-column prop="name" label="昵称" width="180">
          </el-table-column>
          <el-table-column prop="phone" label="手机"> </el-table-column>
          <el-table-column prop="id" label="会员号"> </el-table-column>
          <el-table-column prop="address" label="注册地址"> </el-table-column>
          <el-table-column prop="date" label="注册日期"> </el-table-column>
          <el-table-column label="操作事项">
            <template slot-scope="scope">
              <el-button
                size="mini"
                @click="handleEdit(scope.$index, scope.row)"
                >编辑</el-button
              >
              <el-button
                size="mini"
                type="danger"
                @click="handleDelete(scope.$index, scope.row)"
                >删除</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          background
          layout="prev, pager, next"
          :page-size="pagesize"
          :total="totleData.length"
          @current-change="handleCurrentChange"
          @size-change="handleSizeChange"
        >
        </el-pagination>
      </div>
    </div>
  </div>
  
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';
import TopHeader from "./TopHeader";
// import {} from "../data/api"
export default {
  //import引入的组件需要注入到对象中才能使用
  components: {
    "top-header": TopHeader,
  },
  data() {
    //这里存放数据
    return {
      totleData: [],
      menberData: [], //收藏列表
      pagesize: 4,
      currpage: 1,
      inputVal: "",
    };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    handleCurrentChange(cpage) {
      this.currpage = cpage;
      this.getmenberData();
    },
    handleSizeChange(psize) {
      this.pagesize = psize;
    },
    handleDelete(index, row) {
      this.$axios.delete(`/menberData/${row.id}`).then(() => {
        this.$message({
          type: "success",
          message: "删除成功",
        });
      });
    },
    getmenberData() {
      this.$axios.get("/menberData").then((res) => {
        this.totleData = res;
        this.menberData = res.slice(
          (this.currpage - 1) * this.pagesize,
          this.currpage * this.pagesize
        );
      });
    },
    handelser() {
      return (this.menberData = this.menberData.filter(
        (item) => item.name.indexOf(this.inputVal) > -1
      ));
    },
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {},
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
    this.getmenberData();
  },
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style lang='scss' scoped>
.collect-box {
  .cell {
    text-align: center;
  }
  width: 1220px;
  height: 500px;
  margin: 10px;
  background-color: white;
  border-top: 5px solid blue;
  .box-top {
    display: flex;
    justify-content: space-between;
    width: 100%;
    height: 25px;
    padding: 10px;
    border-bottom: 1px solid #ccc;
    .input {
      margin-right: 80px;
      border: 1px solid #ccc;
      input {
        width: 120px;
        border: none;
        height: 86%;
        outline: none;
      }
      button {
        border: none;
        height: 100%;
      }
    }
  }
  .el-pagination {
    background: white;
    width: 99.2%;
  }
}
</style>